package com.lovo;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class Test05 {
    public static void main(String[] args) {
        // Properties和其他Map集合的不同：
        // 1. Properties提供专门对字符串进行存取的方法
        // 2. Properties可以利用输入输出流实现键值对的输入和输出

        Properties properties = new Properties();
//        properties.setProperty("name","张三");
//        properties.setProperty("age","20");
//        properties.setProperty("gender","男");
//
//        String name = properties.getProperty("name");
//        String age = properties.getProperty("age");
//
//        FileOutputStream fos = null;
//        try {
//            fos = new FileOutputStream("1.properties");
//            properties.store(fos,null);
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        } finally {
//            if(fos != null){
//                try {
//                    fos.close();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//
//        System.out.println(name + " " + age);

        FileInputStream fis = null;
        try {
            fis = new FileInputStream("1.properties");
            properties.load(fis);

            System.out.println(properties.getProperty("name"));
            System.out.println(properties.getProperty("age"));
            System.out.println(properties.getProperty("phone"));
            System.out.println(properties.getProperty("gender"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(fis != null){
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }


        // 将下面字符串?后面的键值对保存到proerties文件中
        String url = "http://www.lovo.com/index?name=aaaaaa&age=20&gender=男";

    }
}
